import 'package:flutter/material.dart';

import 'conststack.dart' show Constants;

class NavigationIconView{
  final String _title;
  final IconData _activeIcon;
  final IconData _icon;
  final BottomNavigationBarItem item;

  NavigationIconView({Key key,String title,IconData icon,IconData activeIcon}):
      _title = title,
      _icon = icon,
      _activeIcon = activeIcon,
      item = new BottomNavigationBarItem(
        icon: Icon(icon),
        activeIcon: Icon(activeIcon),
        title: Text(title),
        backgroundColor: Colors.white
      );
}

class HomeScreen extends StatefulWidget{
  _HomeScreenState createState() => _HomeScreenState();
}


class _HomeScreenState extends State<HomeScreen>{

  List<NavigationIconView> _navigationViews;

  void initState(){
    super.initState();
    _navigationViews = [
      NavigationIconView(
          title: '微信',
          icon: IconData(
            0xe608,
            fontFamily: Constants.IconFontFamily
          ),
          activeIcon: IconData(
            0xe603,
              fontFamily: Constants.IconFontFamily
          )

      ),
      NavigationIconView(
          title: '通讯录',
          icon: IconData(
              0xe608,
              fontFamily: Constants.IconFontFamily
          ),
          activeIcon: IconData(
              0xe603,
              fontFamily: Constants.IconFontFamily
          )
      ),
      NavigationIconView(
          title: '发现',
          icon: IconData(
              0xe608,
              fontFamily: Constants.IconFontFamily
          ),
          activeIcon: IconData(
              0xe603,
              fontFamily: Constants.IconFontFamily
          )
      ),
      NavigationIconView(
          title: '我的',
          icon: IconData(
              0xe608,
              fontFamily: Constants.IconFontFamily
          ),
          activeIcon: IconData(
              0xe603,
              fontFamily: Constants.IconFontFamily
          )
      ),
    ];
  }

  @override


  Widget build(BuildContext context) {

    final BottomNavigationBar botNavBar = BottomNavigationBar(
      items: _navigationViews.map((NavigationIconView view){
        return view.item;
      }).toList(),
      currentIndex: 0,
      type: BottomNavigationBarType.fixed,
      onTap: (int index){
        print('点击的是$index个tap');
      },
    );
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('微信'),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.search),
            onPressed: (){
              print('点击了搜索按钮');
            },
          ),
          IconButton(
            icon: Icon(Icons.add),
            onPressed: (){
              print('先试下啦图标');
            },
          )
        ],
      ),
      body: Container(
        color: Colors.red,
      ),
      bottomNavigationBar: botNavBar,
    );
  }
}